package cn.wolfcode._IOday01_.homeWork;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class FileInputStream00 {
    public static void main(String[] args) throws IOException {
        //InputStream输入流
        //方式1
        File file = new File("9527.txt");
        FileInputStream inputStream = new FileInputStream(file);
        int read1 = inputStream.read();
        int read2 = inputStream.read();
        int read3 = inputStream.read();
        int read4 = inputStream.read();
        System.out.println((char)read1);
        System.out.println((char)read2);
        System.out.println((char)read3);
        System.out.println((char)read4);
        //方式2 没有缓存,读一个打印一个(一般般)
        //int len ;
        //while ((len = inputStream.read()) != -1){
        //    System.out.println("len = " + (char)len);
        //}
        //方式3 浪费内存 , 不确定个数
        byte[] b = new byte[100];
        while (inputStream.read(b) != -1){
            System.out.println("new String(b) = " + new String(b));
        }
        //方式4
        //byte[] b1 = new byte[1];
        //int off = 0 ;
        //int length ;
        //while ((length = inputStream.read(b1)) != -1){
        //    System.out.println("new String (b1,0,length) = " + new String(b1, 0, length));
        //}
        inputStream.close();
    }
}
